package com.test34_类加载器.net.server;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class MessageServer {
    private static final String CLASS_FILE_PATH = "F:" + File.separator + "muyan" + File.separator + "Message.class";

    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(9999);
        System.out.println("开启网络服务器，等待客户端访问......");
        Socket client = serverSocket.accept();  // 进入到阻塞状态，等待客户端连接
        File classFile = new File(CLASS_FILE_PATH);
        InputStream input = new FileInputStream(classFile);
        OutputStream output = client.getOutputStream();     // 获取客户端输出流
        byte[] data = new byte[200];
        int len = 0;
        while ((len = input.read(data)) != -1) {
            output.write(data, 0, len);
        }
        client.shutdownOutput();    // 当数据响应完成之后，关闭连接
        serverSocket.close();   // 关闭服务器
    }
}
